home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / drivers2.zip / PKTADDR.ASM < prev    next >
Assembly Source File  |  1992-01-23  |  4KB  |  184 lines

  1. version    equ    1
  2.  
  3. ;  Copyright, 1989-1992, Russell Nelson, Crynwr Software
  4.  
  5. ;   This program is free software; you can redistribute it and/or modify
  6. ;   it under the terms of the GNU General Public License as published by
  7. ;   the Free Software Foundation, version 1.
  8. ;
  9. ;   This program is distributed in the hope that it will be useful,
  10. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;   GNU General Public License for more details.
  13. ;
  14. ;   You should have received a copy of the GNU General Public License
  15. ;   along with this program; if not, write to the Free Software
  16. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.     include    defs.asm
  19.  
  20. code    segment word public
  21.     assume    cs:code, ds:code
  22.  
  23.     org    80h
  24. phd_dioa    label    byte
  25.  
  26.     org    100h
  27. start:
  28.     jmp    start_1
  29.  
  30. copyleft_msg    label    byte
  31.  db "Packet address version ",'0'+(majver / 10),'0'+(majver mod 10),".",'0'+version," copyright 1990, Russell Nelson.",CR,LF
  32.  db "This program is free software; see the file COPYING for details.",CR,LF
  33.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  34. crlf_msg    db    CR,LF,'$'
  35.  
  36. int_pkt    macro
  37.     pushf
  38.     cli
  39.     call    their_isr
  40.     endm
  41.  
  42. their_isr    dd    ?
  43. packet_int_no    db    ?,?,?,?
  44. ether_bdcst    db    EADDR_LEN dup(-1)    ;ethernet broadcast address.
  45. ether_addr    db    EADDR_LEN dup(-1)
  46.  
  47. handle        dw    ?
  48.  
  49. bogus_type    db    0,0        ;totally bogus type code.
  50.  
  51. signature    db    'PKT DRVR',0
  52. signature_len    equ    $-signature
  53. no_signature_msg    db    "No packet driver at that address",'$'
  54. usage_msg    db    "usage: pktaddr <packet_int_no> [<addr>]",'$'
  55.  
  56. eaddr_msg    db    "My Ethernet address is ",'$'
  57.  
  58. usage_error:
  59.     mov    dx,offset usage_msg
  60. error:
  61.     mov    ah,9
  62.     int    21h
  63.     int    20h
  64.  
  65. start_1:
  66.     cld
  67.  
  68.     mov    dx,offset copyleft_msg
  69.     mov    ah,9
  70.     int    21h
  71.  
  72.     mov    si,offset phd_dioa+1
  73.     cmp    byte ptr [si],CR    ;end of line?
  74.     je    usage_error
  75.  
  76.     mov    di,offset packet_int_no
  77.     call    get_number
  78.  
  79.     mov    di,offset ether_addr
  80.     push    ds
  81.     pop    es
  82.     call    get_eaddr
  83.  
  84.     mov    ah,35h            ;get their packet interrupt.
  85.     mov    al,packet_int_no
  86.     int    21h
  87.     mov    their_isr.offs,bx
  88.     mov    their_isr.segm,es
  89.  
  90.     lea    di,3[bx]
  91.     mov    si,offset signature
  92.     mov    cx,signature_len
  93.     repe    cmpsb
  94.     je    have_signature
  95.     mov    dx,offset no_signature_msg
  96.     jmp    error
  97. have_signature:
  98.  
  99.     push    ds
  100.     pop    es
  101.     mov    cx,EADDR_LEN
  102.     mov    si,offset ether_addr
  103.     mov    di,offset ether_bdcst
  104.     repe    cmpsb
  105.     je    get_mode        ;no address specified.
  106.  
  107.     mov    ah,25            ;set the ethernet address.
  108.     mov    di,offset ether_addr
  109.     mov    cx,EADDR_LEN
  110.     int_pkt
  111.     call    fatal_error
  112.     jmp    okay
  113. get_mode:
  114.     mov    ah,2            ;access all packets.
  115.     mov    al,1            ;Ethernet class.
  116.     mov    bx,-1            ;generic type.
  117.     mov    dl,0            ;generic number.
  118.     mov    cx,2            ;use a type length of 2
  119.     mov    si,offset bogus_type
  120.     push    cs            ;es:di -> our receiver.
  121.     pop    es
  122.     mov    di,offset our_recv
  123.     int_pkt
  124.     call    fatal_error
  125.     mov    handle,ax
  126.  
  127.     mov    ah,6            ;get the ethernet address.
  128.     mov    di,offset ether_addr
  129.     mov    cx,EADDR_LEN
  130.     mov    bx,handle
  131.     int_pkt
  132.     jc    bad
  133.  
  134.     mov    dx,offset eaddr_msg
  135.     mov    ah,9
  136.     int    21h
  137.  
  138.     mov    si,offset ether_addr
  139.     call    print_ether_addr
  140.  
  141.     mov    dx,offset crlf_msg    ;can't depend on DOS to newline for us.
  142.     mov    ah,9
  143.     int    21h
  144.     jmp    short now_close
  145. bad:
  146.     call    print_error
  147. now_close:
  148.     mov    ah,3            ;release_type
  149.     mov    bx,handle
  150.     int_pkt
  151.     call    fatal_error
  152.  
  153. okay:
  154.     int    20h
  155.  
  156.  
  157. our_recv:
  158.     or    ax,ax            ;first or second call?
  159.     jne    our_recv_1        ;second -- we ignore the packet
  160.     push    cs
  161.     pop    es
  162.     mov    di,offset our_buffer
  163. our_recv_1:
  164.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  165.  
  166.  
  167.     include    printea.asm
  168.  
  169.     assume    ds:code
  170.  
  171.     include    pkterr.asm
  172.     include    getea.asm
  173.     include    getnum.asm
  174.     include    skipblk.asm
  175.     include    getdig.asm
  176.     include    digout.asm
  177.     include    chrout.asm
  178.  
  179. our_buffer    label    byte
  180.  
  181. code    ends
  182.  
  183.     end    start
  184.